package com.easemob.chat;

import android.content.Context;
import android.os.Process;
import android.util.Log;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

class EMMonitor
{
  private static EMMonitor _instance = null;
  private static String FILENAME = "pid";
  private static final String TAG = "EMMonitor";
  private boolean isLibraryLoaded = false;
  private Context mContext;

  static EMMonitor getInstance()
  {
    if (_instance == null)
    {
      _instance = new EMMonitor();
      _instance.loadLibrary();
    }
    return _instance;
  }

  void start(Context paramContext, String paramString)
  {
    if (!this.isLibraryLoaded)
      return;
    this.mContext = paramContext;
    if (!matchPid())
    {
      startMonitor(paramString);
      saveCurrentPid();
    }
  }

  private void loadLibrary()
  {
    try
    {
      System.loadLibrary("easemobservice");
      this.isLibraryLoaded = true;
    }
    catch (Throwable localThrowable)
    {
      this.isLibraryLoaded = false;
    }
  }

  private native void startMonitor(String paramString);

  private boolean matchPid()
  {
    int i = 0;
    try
    {
      FileInputStream localFileInputStream = this.mContext.openFileInput(FILENAME);
      i = localFileInputStream.read();
      localFileInputStream.close();
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    Log.w("EMMonitor", " read pid is" + i);
    return i == Process.myPid();
  }

  private void saveCurrentPid()
  {
    try
    {
      FileOutputStream localFileOutputStream = this.mContext.openFileOutput(FILENAME, 0);
      Log.w("EMMonitor", " write pid is" + Process.myPid());
      localFileOutputStream.write(Process.myPid());
      localFileOutputStream.close();
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.EMMonitor
 * JD-Core Version:    0.6.1
 */